package com.lcm.weam.controller.sys;

import com.lcm.weam.entity.resp.Result;
import com.lcm.weam.entity.resp.ResultCode;
import com.lcm.weam.entity.sys.Role;
import com.lcm.weam.service.sys.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色接口
 *  1、邮箱验证成功后修改用户的角色
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/sys/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/addRole", method = RequestMethod.PUT)
    public Result addRole(@RequestBody Role role) {
        roleService.addRole(role);
        return new Result(ResultCode.SUCCESS);
    }

    @RequestMapping(value = "/updateRole/{rid}", method = RequestMethod.POST)
    public Result updateRole(@RequestBody Role role, @PathVariable Integer rid) {
        roleService.updateRole(role, rid);
        return new Result(ResultCode.SUCCESS);
    }

    @RequestMapping(value = "/selectAllRole", method = RequestMethod.GET)
    public Result selectAllRole() {
        List<Role> roles = roleService.selectAllRole();
        return new Result(ResultCode.SUCCESS, roles);
    }

    @RequestMapping(value = "/selectOneRole/{rid}", method = RequestMethod.GET)
    public Result selectOneRole(@PathVariable Integer rid) {
        Role role = roleService.selectRoleById(rid);
        return new Result(ResultCode.SUCCESS, role);
    }

    @RequestMapping(value = "/deleteRole/{rid}", method = RequestMethod.POST)
    public Result deleteRole(@PathVariable Integer rid){
        System.out.println(rid);
        roleService.deleteRole(rid);
        return new Result(ResultCode.SUCCESS);
    }
    
}
